const User = require("../model/user_model")

exports.registerApi = async (qq_account,nick_name)=>{
    return new User({
        qq_account,
        nick_name
    }).save();
}


exports.loginApi = async (qq_account) => {
    return await User.findOne({qq_account})
}

exports.getUserFriendsApi = async (_id) => {
    const friendIds = await User.findOne({_id})
    return Promise.resolve({
        u:friendIds,
        friendIds:friendIds?.good_friends,
        friends:await User.find({_id:{$in:friendIds?.good_friends}},{good_friends:0})
    })
}

exports.addFriendApi = async (myId,friendId) => {
    return await User.updateOne({_id:myId},{$addToSet:{ good_friends:friendId}})
}

/*
 *  statusText 取值为  online | outline 
 */
exports.updateLineStatusApi = async (_id,line_status) => {
    return await User.updateOne({_id},{line_status})
}

exports.getUserIdByQq = async (qq_account) => {
    return await User.findOne({qq_account},{qq_account:0,nick_name:0,line_status:0,good_friends:0})
}